<?php
//calendar events
$deadline_events =" [";
$appearance_events = " [";
foreach ($products as $product){
	$clientcharge = Doctrine_Core::getTable("ClientCharge")->find(array($product->getClientcharge_id()));
	$agentcharge = Doctrine_Core::getTable("AgentCharge")->find(array($product->getAgentcharge_id()));
	$blogger = Doctrine_Core::getTable("Blogger")->find(array($product->getBlogger_id()));
	$client = Doctrine_Core::getTable("Client")->find(array($clientcharge->getClient_id()));

	$deadline_events .= "{ title :'".$blogger->getName()."---".$client->getName()."',";
	$appearance_events .= "{ title :'".$blogger->getName()."---".$client->getName()."',";

	$deadline_events .= "start  :new  Date('".$product->getDeadline()."'),";

	$appearance_events .= "start  :new  Date('".$product->getStartdate()."'),";
	$appearance_events .= "start  :new  Date('".$product->getEnddate()."'),";
	$appearance_events .= "allDay: false,";

	$deadline_events .= "className: '".$sf_user->getAttribute("id")."',";
	$appearance_events .= "className: '".$sf_user->getAttribute("id")."',";

	$deadline_events .= "url :'".url_for("product_show",$product)."'},";
	$appearance_events .= "url :'".url_for("product_show",$product)."'},";
}
$deadline_events .="{}";
$appearance_events .= "{}";
$deadline_events .="]";
$appearance_events .= "]";

//users
$userList="";
$count = count($users);
for($i = 0; $i<$count; $i++){
	$userList .= $users[$i];
	if($i != $count -1)
	$userList .=",";
}
?>

<script type='text/javascript'>
var isDeadline = true;
$(document).ready(function() {

	function deadlineCalendar(){
		$('#calendar').html("");
		$('#calendar').fullCalendar({
			theme : true,
			header : {
				left : 'prev,next today',
				center : 'title',
				right : 'month,agendaWeek,agendaDay'
			},
			selectable: true,
			editable : true,
			select: function(start,end,allDay){
				 window.location="/frontend_dev.php/product/new?start="+start+"&end="+end+"&allDay="+allDay;
			
			},
			eventClick: function(event){
				//alert(event.title);
				return true;
			},
			events : <?= $deadline_events?>
			
			/*
				google calendar
				eventSources:[$.fullCalendar.gcalFeed("http://www.google.com/calendar/feeds/nghialv.bk%40gmail.com/public/basic")]
			*/
		});
	}

	function appearanceCalendar(){
		$('#calendar').html("");
		$('#calendar').fullCalendar({
			theme : true,
			header : {
				left : 'prev,next today',
				center : 'title',
				right : 'month,agendaWeek,agendaDay'
			},
			selectable: true,
			editable : true,
			select: function(start,end,allDay){
				window.location="/frontend_dev.php/product/new?start="+start+"&end="+end+"&allDay="+allDay;
			},
			eventClick: function(event){
				//alert(event.title);
				return true;
			},
			events :<?= $appearance_events?>
		});

		//event theme 
		var uname ="user";
		//fc-event fc-event-hori fc-corner-left fc-corner-right user ui-draggable
/*
		$(".fc-agenda ."+uname+" .fc-event-time").css("background-color","red");
		$(".fc-agenda ."+uname+" .fc-event-time").css("border-color","red");
		$(".fc-agenda ."+uname+" .fc-event-time").css("color","yellow");
		
		$("."+uname+" a").css("background-color","red");
		$("."+uname+" a").css("border-color","red");
		$("."+uname+" a").css("color","yellow");*/

		$(".user").css("background-color","red");
		$(".user").css("border-color","red");
		$(".user").css("color","yellow"); 

		$(".fc-agenda .user .fc-event-time").css("background-color","red");
		$(".fc-agenda .user .fc-event-time").css("border-color","red");
		$(".fc-agenda .user .fc-event-time").css("color","yellow");
		
		$(".user a").css("background-color","red");
		$(".user a").css("border-color","red");
		$(".user a").css("color","yellow");
		
	}
	$("#appearance_time").css("background","#ed3b3b");
	$("#deadline").click(function(event){
		$(this).css("background","#ed3b3b");
		$("#appearance_time").css("background","#8befe9");
		isDeadline = true;
		deadlineCalendar();
	});
	$("#appearance_time").click(function(event){
		$(this).css("background","#ed3b3b");
		$("#deadline").css("background","#8befe9");
		isDeadline = false;
		appearanceCalendar();
	});

	appearanceCalendar();

    /*	
 	var users = "<?php echo $userList?>";
	var uList = users.split(",");
	var len = uList.length;
	for(var i = 0; i<len; i++){
		var uname = uList[i];
		$("."+uname).css("background","red");
		$("."+uname+" a").css("color","yellow");
	}
	*/
});
</script>

<!-- end #menu -->
<div class="time_option">
	<button id="appearance_time" class="button">掲載開始時間</button>
	<button id="deadline" class="button">下書き提出日</button>

</div>

<!-- calendar -->
<div id="calendar"
	style="width: 900px; margin: 0 auto;"></div>
<!-- end #calendar -->

